﻿//////////////////////////////////////////////////////////////////////////////////
//
// Project            : SilverlightAsyncSave
// Module             : SilverlightAsyncSave
// Description        : ViewModel.
// 
// Repository         : $URL$
// Last changed by    : $LastChangedBy$
// Revision           : $LastChangedRevision$
// Last Changed       : $LastChangedDate$
// Author             : $Author$
//
// Id                 : $Id$
//
// Copyright          : (c) 2010 Torsten Bär
//
// Published under the MIT License. See license.txt or http://www.opensource.org/licenses/mit-license.php.
//
//////////////////////////////////////////////////////////////////////////////////
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace SilverlightAsyncSave
{
   /// <summary>
   /// ViewModel.
   /// </summary>
   public class ViewModel : INotifyPropertyChanged
   {
      /// <summary>
      /// Occurs when a property value changes.
      /// </summary>
      public event PropertyChangedEventHandler PropertyChanged;

      private string selectedFile;
      /// <summary>
      /// Gets or sets the selected file.
      /// </summary>
      /// <value>The selected file.</value>
      public string SelectedFile
      {
         get { return selectedFile; }
         set
         {
            if (selectedFile != value)
            {
               selectedFile = value;
               RaisePropertyChanged("SelectedFile");
            }
         }
      }

      private ObservableCollection<string> fileItems;
      /// <summary>
      /// Gets or sets the file items.
      /// </summary>
      /// <value>The file items.</value>
      public ObservableCollection<string> FileItems
      {
         get { return fileItems; }
         set
         {
            if (fileItems != value)
            {
               fileItems = value;
               RaisePropertyChanged("FileItems");
               SelectedFile = null;
            }
         }
      }

      /// <summary>
      /// Raises the property changed event.
      /// </summary>
      /// <param name="propertyName">Name of the property.</param>
      protected void RaisePropertyChanged(string propertyName)
      {
         if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
   }
}